/**
 * @Created by 
 * @updated by
 * @description 批量重跑方案管理
 */
define(function (require, exports) {
	/**
	 * 页面加载完成时触发
	 * @param hashCode 路由ID
	 * @param data 传递数据对象
	 * @param cite 页面站点信息
	 */
    exports.ready = function (hashCode, data, cite) {
        yufp.lookup.reg('USE_TASK_RUN_STATE');
        yufp.custom.vue({
            el: cite.el,
            data: function () {
                return {
                    // 数据对象
                    runFormData: {},
                    searchFormdata: {},
                    sortColunms: {
                        'appName': 'APP_NAME',
                        'groupName': 'GROUP_NAME',
                        'cyclePnt': 'CYCLE_PNT',
                        'estCnt': 'EST_CNT',
                        'queneCnt': 'QUENE_CNT',
                        'execCnt': 'EXEC_CNT',
                        'successCnt': 'SUCCESS_CNT',
                        'failedCnt': 'FAILED_CNT',
                        'unknowCnt': 'UNKNOW_CNT',
                        'waitCnt': 'WAIT_CNT',
                        'currentCnt': 'CURRENT_CNT',
                        'runState': 'RUN_STATE'
                    },
                    sortTypes: {
                        'descending': 'desc',
                        'ascending': 'asc'
                    },
                    // 权限控制
                    runFnShow: data.runFnShow,
                    // 数据展示
                    wftRunDataUrl: "api/use/app/jobRedo/runningList",
                    // 页面控制
                    loading: false
                }
            },
            mounted() {
                var _this = this;
                _this.runFormData.schemeCode = data.schemeCode;
                _this.runFormData.schemeName = data.schemeName;
                _this.searchFormdata.schemeCode = data.schemeCode;
                var param = { condition: JSON.stringify(_this.searchFormdata) };
                _this.$refs.wftRunRefTable.remoteData(param);
            },
            methods: {
                reloadData: function () {
                    var _this = this
                    var param = { condition: JSON.stringify(_this.searchFormdata) };
                    _this.$refs.wftRunRefTable.remoteData(param);
                },
                // 排序
                wftRunSort: function (column) {
                    var _this = this
                    _this.searchFormdata.sortColunm = _this.sortColunms[column.prop];
                    _this.searchFormdata.sorType = _this.sortTypes[column.order];
                    var param = { condition: JSON.stringify(_this.searchFormdata) };
                    _this.$refs.wftRunRefTable.remoteData(param);
                },
                // 作业列表
                showTask: function (row, jobState) {
                    var _this = this;
                    var customKey = 'custom_' + row.coreId + row.cycleNo;
                    var routeId = 'router_' + row.coreId + row.cycleNo;
                    var url = 'pages/use/monitors/taskMonitor/taskMonitorList/taskMonitorList';
                    if (!(jobState instanceof Object)) {
                        row.searchState = jobState;
                    }
                    row.redoBnt = _this.runFnShow;
                    row.interruptBnt = _this.runFnShow;
                    row.forceSuccessBnt = _this.runFnShow;
                    row.preValueBnt = _this.runFnShow;
                    row.unPreValueBnt = _this.runFnShow;
                    row.forceJobValueBnt = _this.runFnShow;
                    row.jobParamBnt = _this.runFnShow;
                    row.jobPriorBnt = _this.runFnShow;
                    yufp.router.addRoute(routeId, {
                        html: url + '.html',
                        js: url + '.js'
                    });
                    row.customKey = customKey;
                    yufp.frame.addTab({
                        id: routeId, // 菜单功能ID（路由ID）
                        key: customKey, // 自定义唯一页签key,请统一使用custom_前缀开头
                        // title: row.appName + '_流程图', // 页签名称
                        title: '[' + row.groupName + ']作业清单', // 页签名称
                        data: yufp.clone({ routeId: routeId, title: '[' + row.groupName + ']作业清单' }, row)// 传递的业务数据，可选配置
                    });
                },
                // tips
                renderHeader: function (h, { column, $index }) {
                    var tips = ['', '', '', '', '', '',
                        '预估总数=当前任务包含的作业数',
                        '当前总数=等待+队列+执行+成功+失败+未知',
                        '等待总数',
                        '队列总数',
                        '执行总数',
                        '成功总数',
                        '失败总数',
                        '未知总数',
                    ]
                    return (
                        h('span', [
                            h('span', column.label + ' '),
                            h('yu-tooltip', {
                                props: {
                                    effect: 'light',
                                    content: tips[$index],
                                    placement: 'top'
                                }
                            }, [
                                    h('i', {
                                        class: 'el-icon-yx-question'
                                    })
                                ])
                        ])
                    )
                },
                showFlowChart: function (row) {
                    var _this = this;
                    yufp.service.request({
                        url: backend.useService + '/monitor/taskMonitor/queryFlowChart',
                        method: 'get',
                        data: {
                            coreId: row.coreId,
                            cycleNo: row.cycleNo,
                            groupCode: row.groupCode,
                            appCode: row.appCode
                        },
                        callback: function (code, message, response) {
                            if (!response.data) {
                                _this.$message({ message: '流程图数据为空！', type: 'warning', duration: 6000 });
                                return;
                            } else {
                                var customKey = 'custom_' + row.coreId + row.cycleNo;
                                var routeId = 'router_' + row.coreId + row.cycleNo;
                                var url = 'pages/use/monitors/taskMonitor/taskMonitorGraph/taskMonitorGraph';
                                yufp.router.addRoute(routeId, {
                                    html: url + '.html',
                                    js: url + '.js'
                                });
                                row.customKey = customKey;
                                row.runFnButton = true;
								row.isHistory = false;
                                yufp.frame.addTab({
                                    id: routeId, // 菜单功能ID（路由ID）
                                    key: customKey, // 自定义唯一页签key,请统一使用custom_前缀开头
                                    title: row.groupName, // 页签名称
                                    data: yufp.clone({ routeId: routeId }, row)// 传递的业务数据，可选配置
                                });
                            }
                        }
                    });
                },
                redoFlowChart: function (row) {
                    var url = "api/use/monitor/taskMonitor/redoRunAllTask";
                    this.commonRunTask(row, url);
                },
                interruptFlowChart: function (row) {
                    var url = "api/use/monitor/taskMonitor/interruptAllTask";
                    this.commonRunTask(row, url);
                },
                deleteFlowChart: function (row) {
                    var url = "api/use/monitor/taskMonitor/deleteRunTask";
                    this.commonRunTask(row, url);
                },
                commonRunTask: function (row, url) {
                    var _this = this;
                    _this.loading = true;
                    yufp.service.request({
                        method: 'GET',
                        url: url,
                        data: row,
                        callback: function (code, message, response) {
                            _this.loading = false;
                            if (response.code != 0) {
                                _this.$message({ message: response.message, type: "warning" });
                            } else {
                                _this.$message("操作成功");
                                _this.reloadData();
                            }
                        }
                    });
                },
            }
        });
    }
});
